package artid.com.arttogoa.adapter;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import artid.com.arttogoa.R;
import artid.com.arttogoa.parser.ConsultationList;
import artid.com.arttogoa.util.AppUtil;
import artid.com.arttogoa.volley.BitmapCache;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.bumptech.glide.Glide;

public class ZxAdapter extends BaseAdapter{
	private Context mContext;
	LayoutInflater mInflater;
	ViewHolder holder;
	private ImageLoader mImageLoader;
	List<ConsultationList> listdata;

	public ZxAdapter(Context mContext) {
		this.mContext = mContext;
		listdata = new ArrayList<ConsultationList>();
		RequestQueue mQueue = Volley.newRequestQueue(mContext);
		mImageLoader = new ImageLoader(mQueue, new BitmapCache());
		mInflater = LayoutInflater.from(mContext);
	}



	public void setdata(List<ConsultationList> listdata) {
		this.listdata = listdata;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return listdata.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh = null; 
		if (convertView == null) {
			vh = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_art_zx, null);
			vh.tittle = (TextView) convertView.findViewById(R.id.title_xz);
			vh.time = (TextView) convertView
					.findViewById(R.id.text_zx_date);
			vh.name = (TextView) convertView
					.findViewById(R.id.text_zx_name);
			vh.sh = (TextView) convertView
					.findViewById(R.id.text_zx_sh);
			vh.imgurl = (ImageView) convertView.findViewById(R.id.image_item_zx);
			vh.share = (ImageView)convertView.findViewById(R.id.iv_zx_share);
			convertView.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}
		final ConsultationList item = listdata.get(position);
		vh.tittle.setText(item.getTitle());
		vh.time.setText(item.getCreate_time());
		vh.name.setText(item.getRealname());
		if (item.getState().equals("1")) {
			vh.sh.setText("审核中");	
		}else if (item.getState().equals("2")) {
			vh.sh.setText("审核中");
		}else if (item.getState().equals("3")) {
			vh.sh.setText("审核通过");
		}else if (item.getState().equals("4")) {
			vh.sh.setText("未通过审核");
		}
		Glide.with(mContext).load(item.getImgurl()+AppUtil.picWidthUrl)
		.placeholder(R.drawable.yspba_img_mor)
		.error(android.R.drawable.ic_delete).into(vh.imgurl);

		// ImageListener listener = ImageLoader
		// .getImageListener(vh.imgurl, R.drawable.yspba_img_mor,
		// android.R.drawable.ic_delete);
		// mImageLoader.get( item.getImgurl()+AppUtil.picWidthUrl,
		// listener);
		vh.share.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				AppUtil.showShare(mContext, item.getTitle(), item.getTitle(), item.getImgurl(),
						item.getSharelink());
			}
		});
		return convertView;
	}

	class ViewHolder {
		TextView tittle, time, name, sh;
		ImageView imgurl,share;
	}

}
